package tichu_project252.View.Player;

import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.io.IOException;
import java.util.LinkedList;
import javax.swing.JPanel;
import javax.swing.border.LineBorder;
import tichu_project252.CardClasses.Card;
import tichu_project252.Model.Model;

/**This class implements the JPanel that contains the cards and buttons of the player. 
 * Here we define where all the buttons wil be.
 *
 *
 * @author Alexandra Barka, ΑΜ: 2867, login : barka.
 * @version %I%, %G%
*/
public class PlayerPanel extends JPanel {

    private CardContainer cards = null;
    private controlButtons buttons = null;
    private int player;
/**
 * Constructs a new JPanel where we add the Cards and the Buttons of the player.
 * 
 * @param m The model
 * @param n The player
 * @throws IOException if a mistake occurs
 */
    public PlayerPanel(Model m, int n) throws IOException {
        super();
        cards = new CardContainer(m, n, 25);
        buttons = new controlButtons(m,n);
        this.player = n;

        this.setLayout(new GridBagLayout());

        GridBagConstraints d = new GridBagConstraints();

        d.fill = GridBagConstraints.RELATIVE;

        d.gridx = 0;
        d.gridy = 0;
        this.add(cards, d);


        d.gridx = 1;
        d.gridy = 0;
        this.add(buttons);

        this.setOpaque(false);
        this.setBorder(new LineBorder(Color.BLACK, 1, false));
    }
      /**
     * Sets if the button will be enabled or not
     *
     * <p> <b> Transformer: </b> setEnabled(boolean flag)  </p>
     *
     * <p><b> Precondition: </b> </p>
     *
     * </p> <p> <b> Postcondition:</b> The button is enabled if the flag is true.
     * </p>
     *
     */
    
    @Override
    public void setEnabled(boolean flag) {
        buttons.setEnabled(flag);
    }
    
    /**
     * Add in the Card container cards the Linked list.
     * @param l Linked list with cards
     * @throws IOException if an error occured
     */
    public void addAll(LinkedList<Card> l) throws IOException {
        this.cards.addAll(l);
    }
    
    /**
     * Empty the card container.
     */
    public void clear() {
        cards.clear();
    }
    
    
    /**
     * Clean up the card container.
     */

    public void cleanup() {
        cards.cleanup();
    }
  /**
     * Returns the player.
     *
     * <p> <b> Accessor: </b> getPlayer() </p>
     *
     * <p><b> Precondition: </b> The player is valid</p>
     *
     * </p> <p> <b> Postcondition:</b> Returns the player.
     * </p>
     *
     *
     */
    public int getPlayer() {
        return this.player;
    }
    
      /**
     * Sets if the player have bomb
     *
     * <p> <b> Tranformer: </b> checkBomb() </p>
     *
     * <p><b> Precondition: </b></p>
     *
     * </p> <p> <b> Postcondition:</b> checks if the player have bomb
     * </p>
     *
     */
    public void checkBomb() {
        this.buttons.setBomb(player);
    }

    @Override
    public boolean isOptimizedDrawingEnabled() {
        return false;
    }
}
